using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickUp : MonoBehaviour
{
    private Inventory _inventory;

    public GameObject itemBotton;   //实例化到背包中的物品图片
    

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            _inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
            for (int i = 0; i < _inventory.slots.Length; i++)
            {
                if (_inventory.isFull[i] == false)  //如果背包中当前这个槽没有满
                {
                    //加入当前物品到背包中
                    Instantiate(itemBotton, _inventory.slots[i].transform, false);  //实例化到_inventory.slots[i]子物体的位置
                    Destroy(gameObject);
                    _inventory.isFull[i] = true;
                    break;
                }
            }
        }
    }
}
